//
//  SafeViewController.m
//  test
//
//  Created by 朱圳 on 2018/1/11.
//  Copyright © 2018年 朱圳. All rights reserved.
//

#import "SafeViewController.h"
#import "UpdatePwdVC.h"
#import "LoginViewController.h"
#import "UserManager.h"
#import "LoginViewController.h"
@interface SafeViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(strong,nonatomic)NSArray*list;
@property(nonatomic,strong)UITableView *tableView;

@end

@implementation SafeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.list = @[@"修改密码",@"退出登录"];
    self.title = @"安全中心";
    [self.view addSubview:self.tableView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - Table view data source
    
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}
    
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.list.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *SimpleTableIdentifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
    if (cell ==nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier: SimpleTableIdentifier];
        cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        cell.textLabel.text = self.list[indexPath.row];
    }
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        UpdatePwdVC *vc = [[UpdatePwdVC alloc]init];
        vc.type = @"1";
        [self.navigationController pushViewController:vc animated:YES];
    }
    if (indexPath.row == 1) {
        UIAlertController *alertview=[UIAlertController alertControllerWithTitle:@"确定退出登录？" message:nil preferredStyle:UIAlertControllerStyleAlert];
        
        // 设置按钮
        UIAlertAction *cancel=[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
        UIAlertAction *defult = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

            LoginViewController *vc = [[LoginViewController alloc]init];
            [self presentViewController:vc animated:YES completion:nil];
            [UserManager loginOut];
            [self.tableView reloadData];
        }];
        
        [alertview addAction:cancel];
        [alertview addAction:defult];
        
        [self presentViewController:alertview animated:YES completion:nil];
    }
}
-(UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.backgroundColor = [UIColor whiteColor];
        _tableView.tableFooterView = [[UIView alloc]init];
        _tableView.delegate = self;
        _tableView.dataSource = self;
    }
    return _tableView;
}
@end
